﻿using Abp.Application.Services.Dto;
using Abp.Application.Services;
using System;
using Choucius.Boilerplate9.RubberFrames.Dto;
using Abp.Domain.Repositories;
using Choucius.Boilerplate9.Enum;
using Choucius.Boilerplate9.RubberFrameLogs;

namespace Choucius.Boilerplate9.RubberFrames
{
    /// <summary>
    /// 
    /// </summary>
    public class RubberFrameAppService : AsyncCrudAppService<RubberFrame, RubberFrameDto, Guid, PagedResultRequestDto, CreateUpdateRubberFrameDto, CreateUpdateRubberFrameDto>, IRubberFrameAppService
    {
        private readonly IRepository<RubberFrame, Guid> _repository;
        private readonly IRepository<RubberFrameLog, long> _logRepository;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="repository"></param>
        /// <param name="logRepository"></param>
        public RubberFrameAppService(IRepository<RubberFrame, Guid> repository, IRepository<RubberFrameLog, long> logRepository) : base(repository)
        {
            _repository = repository;
            _logRepository = logRepository;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public RubberFrameCountDto GetStatusCount()
        {
            var result = new RubberFrameCountDto();
            result.Total = _repository.Count();
            result.Undefined = _repository.Count(x => x.Status == LabelStatus.Undefined);
            result.Initialization = _repository.Count(x => x.Status == LabelStatus.Initialization);
            result.InPackStock = _repository.Count(x => x.Status == LabelStatus.InPackStock);
            result.OutPackStock = _repository.Count(x => x.Status == LabelStatus.OutPackStock);
            result.InProductStock = _repository.Count(x => x.Status == LabelStatus.InProductStock);
            return result;
        }
    }
}
